package com.spic.business.violation.supervision.speed.controller;

import com.spic.business.common.core.utils.poi.BusinessExcelUtil;
import com.spic.business.violation.supervision.speed.domain.ViolationsSpeedRules;
import com.spic.business.violation.supervision.speed.service.IViolationsSpeedRulesService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.web.page.TableDataInfo;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 超速规则Controller
 *
 * @author spic
 * @date 2021-10-13
 */
@RestController
@RequestMapping("/violation/speed_rules")
public class ViolationsSpeedRulesController extends BaseController
{
    @Autowired
    private IViolationsSpeedRulesService violationsSpeedRulesService;

    /**
     * 查询超速规则列表
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:list")
    @GetMapping("/list")
    public TableDataInfo list(ViolationsSpeedRules violationsSpeedRules)
    {
        startPage();
        List<ViolationsSpeedRules> list = violationsSpeedRulesService.selectViolationsSpeedRulesList(violationsSpeedRules);
        return getDataTable(list);
    }

    /**
     * 导出超速规则列表
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:export")
    @Log(title = "超速规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ViolationsSpeedRules violationsSpeedRules) throws IOException
    {
        List<ViolationsSpeedRules> list = violationsSpeedRulesService.selectViolationsSpeedRulesList(violationsSpeedRules);
        BusinessExcelUtil<ViolationsSpeedRules> util = new BusinessExcelUtil<ViolationsSpeedRules>(ViolationsSpeedRules.class);
        util.exportExcel(response, list, "超速规则数据");
    }

    /**
     * 获取超速规则详细信息
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(violationsSpeedRulesService.selectViolationsSpeedRulesById(id));
    }

    /**
     * 新增超速规则
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:add")
    @Log(title = "超速规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ViolationsSpeedRules violationsSpeedRules)
    {
        return toAjax(violationsSpeedRulesService.insertViolationsSpeedRules(violationsSpeedRules));
    }

    /**
     * 修改超速规则
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:edit")
    @Log(title = "超速规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ViolationsSpeedRules violationsSpeedRules)
    {
        return toAjax(violationsSpeedRulesService.updateViolationsSpeedRules(violationsSpeedRules));
    }

    /**
     * 删除超速规则
     */
    @PreAuthorize(hasPermi = "business/violation:speed_rules:remove")
    @Log(title = "超速规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(violationsSpeedRulesService.deleteViolationsSpeedRulesByIds(ids));
    }
}
